﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EuroManager.Domain.Simulator.Helpers;
using NUnit.Framework;

namespace EuroManager.Domain.Simulator.Tests.Helpers
{
    [TestFixture]
    public class MathsTests
    {
        [Test]
        public void EpsilonShouldBeGreaterThanZero()
        {
            Assert.Greater(Maths.Epsilon, 0);
        }

        [Test]
        public void ShouldExposePi()
        {
            Assert.AreEqual(3.1415927, Maths.Pi, Maths.Epsilon);
        }

        [Test]
        public void ShouldCalculateAbs()
        {
            Assert.AreEqual(3, Maths.Abs(-3));
        }

        [Test]
        public void ShouldCalculateAcos()
        {
            Assert.AreEqual(Maths.Pi / 2, Maths.Acos(0), Maths.Epsilon);
        }

        [Test]
        public void ShouldCalculateCos()
        {
            Assert.AreEqual(0, Maths.Cos(Maths.Pi / 2), Maths.Epsilon);
        }

        [Test]
        public void ShouldEqualWhenDifferenceLowerThanDelta()
        {
            Assert.IsTrue(Maths.Equals(1, 1.00000001f, 1e-8f));
        }

        [Test]
        public void ShouldNotEqualWhenDifferenceHigherThanDelta()
        {
            Assert.IsFalse(Maths.Equals(1, 1.0000001f, 1e-8f));
        }

        [Test]
        public void ShouldEqualWhenDifferenceIsLessThanEpsilon()
        {
            Assert.IsTrue(Maths.Equals(1, 1 + 0.99f * Maths.Epsilon));
        }

        [Test]
        public void ShouldCalculateMax()
        {
            Assert.AreEqual(3, Maths.Max(3, -4));
        }

        [Test]
        public void ShouldCalculateMin()
        {
            Assert.AreEqual(1, Maths.Min(1, 1.001f));
        }

        [Test]
        public void ShouldCalculateMinMax()
        {
            Assert.AreEqual(5, Maths.MinMax(-3, 12, 5));
            Assert.AreEqual(2, Maths.MinMax(-3, 2, 5));
            Assert.AreEqual(-3, Maths.MinMax(-3, -12, 5));
        }

        [Test]
        public void ShouldCalculateSign()
        {
            Assert.AreEqual(-1, Maths.Sign(-35));
            Assert.AreEqual(0, Maths.Sign(0));
            Assert.AreEqual(1, Maths.Sign(0.00001f));
        }

        [Test]
        public void ShouldCalculateSin()
        {
            Assert.AreEqual(1, Maths.Sin(Maths.Pi / 2));
        }

        [Test]
        public void ShouldCalculateSqrt()
        {
            Assert.AreEqual(9, Maths.Sqrt(81));
        }
    }
}
